package com.sa.app.utilities;

import java.util.Comparator;

import com.sa.app.objects.Item;

public class ComparatorItem implements Comparator<Item> {
	private Integer ordenacion;
	private DataBaseManager db;

	// ordenacion será el elemento a ordenar
	public ComparatorItem(Integer ordenacion, DataBaseManager db) {
		this.ordenacion = ordenacion;
		this.db = db;
	}

	public int compare(Item item1, Item item2) {
		int res = 0;

		// if's para saber por que elementos estamos ordenando
		if (ordenacion.equals(MyApplication.ALIAS)) {
			res = item1.getAliasID().compareTo(item2.getAliasID());
		} else if (ordenacion.equals(MyApplication.MANUFACTURER)) {
			res = item1.getManufacturer().compareTo(item2.getManufacturer());
		} else if (ordenacion.equals(MyApplication.MOST_USED)) {
			res = db.getNumUsesFor(item2.getNfcID()).compareTo(
					db.getNumUsesFor(item1.getNfcID()));
		}
		return res;
	}

}
